package com.freedom.controller.w.core;

import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.freedom.service.core.SysRoleService;
import com.freedom.vo.w.core.SysRoleVo;

@Controller
public class SysRoleController extends BaseWebPaginationCRUDController<SysRoleVo> {
	// 本地异常日志记录对象
	private static final Logger logger = LoggerFactory.getLogger(SysRoleController.class);
	
	@Autowired
	private SysRoleService sysRoleService;
	
	/**
	 * 角色列表初始化跳转
	 */
	@RequiresPermissions("sys:role:view")
	@RequestMapping(value = "wh002/wh021")
	@Override
	public String init() {
		return "role/rolelist";
	}

	/**
	 * 角色列表
	 * @param param
	 * @return
	 */
	@RequiresPermissions("sys:role:view")
	@RequestMapping("wh002/wh022")
	@ResponseBody
	public SysRoleVo roleList(@RequestBody MultiValueMap<String, String> param) {
		SysRoleVo vo = this.getVo();
		Map<String, Object> map = this.initPaginationParam(param);
		try {
			vo.setTotal(sysRoleService.selectDataCountByParam(map));
			vo.setRows(sysRoleService.selectDataListByParam(map));
		} catch (Exception e) {
			// TODO: handle exception
			logger.info("角色列表", e);
		}
		return vo;
	}
	
}
